package com.event.ingestion.config;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author ZzHh
 * @Classname LoadConfig
 * @Description TODO
 * @Date 2020/6/12 10:27
 * @Create by IntelliJ IDEA
 **/

/**
 * 读取配置文件
 */
public class LoadConfig {
    //zookeeper url
    public final static String zookeeperUrl = "zookeeperUrl";

    //broker url
    public final static String kafkaBrokerUrl = "brokerUrl";

    //stateDir
    public final static String stateDir = "stateDir";

    public final static String coreSite = "coreSite";
    public final static String hdfsSite = "hdfsSite";
    public final static String hbaseSite = "hbaseSite";


    //mongo server
    public final static String mongoHost="mongoHost";
    public final static String mongoPort="mongoPort";
    public final static String mongoDatabase="mongoDatabase";
    public final static String mongoUser="mongoUser";
    public final static String mongoPwd="mongoPwd";

    //加载文件内容到properties
    public static Properties loadSettings(String settingsFile) throws IOException {
        Properties prop = new Properties();
        FileInputStream in = new FileInputStream(settingsFile);
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
            try {
                String line = bufferedReader.readLine();
                while (line != null) {
                    String[] values = line.split("=", -1);
                    if ((values != null) && (values.length == 2)) {
                        prop.put(values[0],values[1]);
                    }
                    line = bufferedReader.readLine();
                }
            }finally {
                bufferedReader.close();
            }
        }finally {
            in.close();
        }
        return prop;
    }
}